// todo 实现封装一个axios
import api from '@/utils/axios';
import { GetAccountInfoModel } from './model';
import {
  postData,
  connectTestType,
  insertStopwatchType,
  operationStatus,
  dataCriterionStandard,
  postTree,
  addingDataSources,
  dataAssert,
  dapostData,
  daDataItem,
  interfaceType,
  batchClassify,
  apiTest,
  apiDetailType,
} from '@/pages/CodeTables/specification';

enum Api {
  // 目录菜单
  GET_MENU = 'api//menu/get/listMenu', //菜单列表
  // 码表管理
  CHANGE_STOPWATCHSTATUS = 'api/stopwatch/update/releaseOrOutage', //发布、停用码表
  GET_STOPWATCH = 'api/stopwatch/post/stopwatchList', //查询码表列表
  GET_SHTOPWATCHDETAIL = 'api/stopwatch/get/getStopwatchDetail/', //查看码表详情
  ADD_STOPWATCH = 'api/stopwatch/post/addStopwatch', //新增码表
  DEL_STOPWATCH = 'api/stopwatch/delete/stopwatchList/', //删除码表
  PUT_STOPWATCH = 'api/stopwatch/update/updateStopwatch/', //编辑码表
  DOWNLOAD_STOPWATCH = 'api/stopwatch/get/exportExcel', //导出标准码表
  // 树结构
  GET_DIRECTORY = 'api/directory/get/getDirectoryList/', // 获取树结构目录列表
  ADD_DIRECTORY = 'api/directory/post/addDirectory', // 新增 树结构目录列表
  PUT_DIRECTORY = 'api/directory/update/updateDirectory', // 修改树结构目录列表名称
  DEL_DIRECTORY = 'api/directory/delete/deleteDirectory/', // 删除树结构目录列表
  //数据标准目录
  CHANGE_DATASTANDRDSTATUS = 'api/dataCriterion/update/releaseOrOutage', //发布、停用数据标准
  GET_DATACRITERION = 'api/dataCriterion/post/dataCriterionList', //查询数据标准目录列表
  GET_DATACRITERIONDETAIL = 'api/dataCriterion/get/getDataCriterionDetail/', //查看数据标准详情
  ADD_DATACRITERION = 'api/dataCriterion/post/addDataCriterion', //新增数据标准
  PUT_DATACRITERION = 'api/dataCriterion/update/updateDataCriterion', //编辑数据标准
  DEL_DATACRITERION = 'api/dataCriterion/delete/deleteCriterionDetail/', //删除数据标准
  DOWNLOAD_DATACRITERION = 'api/dataCriterion/get/exportExcel', //导出数据标准表格
  //数据库管理
  CHANGE_DATABASESTATUS = 'api/dataSource/update/releaseOrOutage', //发布、停用数据源
  GET_DATABASE = 'api/dataSource/post/selectDateSourceByPage', //获取数据源列表
  GET_DATABASETYPE = 'api/dataSource/get/findAllDatabaseType', //查询数据库类型列表
  ADD_DATABASE = 'api/dataSource/post/addDataSource', //新增数据源
  DEL_DATABASE = 'api/dataSource/delete/deleteSource/', //删除数据源
  PUT_DATABASE = 'api/dataSource/update/updateDataSource', //编辑数据源信息
  POST_DATABASETEST = 'api/dataSource/post/connectTest', //连接测试数据源
  //数据资产管理
  GET_DATAASSET = 'api/dataAssert/post/selectDataAssertBy', //获取数据资产列表
  CHANGE_DATAASSET = 'api/dataAssert/update/releaseOrOutage', //发布、停用码表

  DEL_DATAASSET = 'api/dataAssert/delete/deleteDataAssert/', //删除数据资产管理
  GET_DATAASSETDETAIL = 'api/dataAssert/get/getDataAssertDetail/', //查询数据资产详情
  ADD_DATAASSERT = 'api/dataAssert/post/createOrUpdateDataAssert', //新增数据资产
  SELECT_DATAASSERT = 'api/dataAssert/post/selectDataAssertBy', //根据条件查询数据资产表
  // 接口管理
  GET_INTERFACEDETAIL = 'api/interface/get/getApiDetail/', //  查看接口详情
  CHANGE_INTERFACESTATUS = 'api/interface/update/releaseOrOutage', //  (批量)发布/停用接口
  UPDATA_BATCHCLASSIFY = 'api/interface/post/batchClassify', //批量分类
  GET_INTERFACE = 'api/interface/post/ApiList', //查询接口列表
  ADD_INTERFACE = 'api/interface/post/createOrUpdateApi', //新增接口
  DEL_INTERFACE = 'api/interface/delete/deleteApi/', //删除接口
  VERIFY_INTERFACE = 'api/interface/post/verifyApiData', //验证接口
  POST_INTERFACETEST = 'api/interface/post/apiTest', //测试接口
  // PUT_DATABASEAPI = 'api/post/updateApi', //编辑接口
  // CHANGE_DATABASE = 'api/update/releaseOrOutage', //发布、停用接口
  // GET_DATABASEAPI = 'api/post/ApiList', //查询接口列表
  // GET_DATABASEAPIDETAIL = 'api/get/getApiDetail/{apiCode}', //查看接口详情
}
/* 获取菜单目录 */
export const getMenu = () => api.get({ url: Api.GET_MENU });
/* 码表*/
// 得到码表管理列表数据
export const getStopwatchList = (data: postData) => api.post<GetAccountInfoModel>({ url: Api.GET_STOPWATCH, data });
// 向数据库添加码表
export const addStopwatch = (data: insertStopwatchType) => api.post<GetAccountInfoModel>({ url: Api.ADD_STOPWATCH, data });
// 修改码表
export const updateStopwatch = (data: insertStopwatchType) => api.put<GetAccountInfoModel>({ url: Api.PUT_STOPWATCH, data });
// 改变码表状态
export const changeStopwatchState = (data: operationStatus) => api.put<GetAccountInfoModel>({ url: Api.CHANGE_STOPWATCHSTATUS, data });
// 得到选择码表的码表配置
export const getStopwatchDetail = (stopwatchCode: string) => api.get<GetAccountInfoModel>({ url: Api.GET_SHTOPWATCHDETAIL + stopwatchCode });
// 删除码表
export const deleteStopwatch = (stopwatchCode: string) => api.del<GetAccountInfoModel>({ url: Api.DEL_STOPWATCH + stopwatchCode });
// 码表模板下载
export const downloadStopwatch = () => api.get<BlobPart>({ url: Api.DOWNLOAD_STOPWATCH, params: { responseType: 'blob' } });
/* 树结构目录列表 */
//获取树型结构目录列表
export const getTree = (menuCode: string) => api.get({ url: Api.GET_DIRECTORY + menuCode });
// 新增树结构目录列表
export const addTree = (data: postTree) => api.post({ url: Api.ADD_DIRECTORY, data });
// 修改树结构目录列表名称
export const putTree = (data: postTree) => api.put({ url: Api.PUT_DIRECTORY, data });
// 删除新增树结构目录列表
export const delTree = (menuCode: string) => api.del({ url: Api.DEL_DIRECTORY + menuCode });

/* 标准目录*/
// 得到数据标准目录列表数据
export const getDataStandardsList = (data: postData) => api.post<GetAccountInfoModel>({ url: Api.GET_DATACRITERION, data });
// 改变标准状态
export const changeStandardsState = (data: operationStatus) => api.put<GetAccountInfoModel>({ url: Api.CHANGE_DATASTANDRDSTATUS, data });
//获取数据标准目录的标准编号下的详情
export const getDataCriterionDetail = (dcCode: string) => api.get<GetAccountInfoModel>({ url: Api.GET_DATACRITERIONDETAIL + dcCode });
//新增数据标准
export const addDataCriterion = (data: dataCriterionStandard) => api.post<GetAccountInfoModel>({ url: Api.ADD_DATACRITERION, data });
//编辑数据标准
export const updateDataCriterion = (data: dataCriterionStandard) => api.put<GetAccountInfoModel>({ url: Api.PUT_DATACRITERION, data });
// 删除数据标准目录
export const delDataCriterion = (dcCode: string) => api.del<GetAccountInfoModel>({ url: Api.DEL_DATACRITERION + dcCode });
// 数据标准模板下载
export const downloadCriterion = () => api.get<BlobPart>({ url: Api.DOWNLOAD_DATACRITERION, params: { responseType: 'blob' } });

/* 数据库管理*/
// 查询数据库管理list
export const getDataBaseList = (data: any) => api.post<GetAccountInfoModel>({ url: Api.GET_DATABASE, data });
//新增数据源
export const addDataBase = (data: addingDataSources) => api.post<GetAccountInfoModel>({ url: Api.ADD_DATABASE, data });
// 改变数据源状态
export const changeDataBaseState = (data: operationStatus) => api.put<GetAccountInfoModel>({ url: Api.CHANGE_DATABASESTATUS, data });
// 删除数据源
export const deleteDataBase = (id: string) => api.del<GetAccountInfoModel>({ url: Api.DEL_DATABASE + id });
// 连通测试
export const postConnectTest = (data: connectTestType) => api.post<object>({ url: Api.POST_DATABASETEST, data });
// 查询数据库类型
export const getDataBaseType = () => api.get<GetAccountInfoModel>({ url: Api.GET_DATABASETYPE });
// 修改数据源
export const putDataBase = (data: addingDataSources) => api.put<GetAccountInfoModel>({ url: Api.PUT_DATABASE, data });

/* 数据资产管理*/
//查询数据资产
export const getDataAssetList = (data: dapostData) => api.post<GetAccountInfoModel>({ url: Api.GET_DATAASSET, data });
//发布、停用
export const upDateAssert = (data: operationStatus) => api.put<daDataItem>({ url: Api.CHANGE_DATAASSET, data });
//新增数据资产
export const addDataAssert = (data: dataAssert) => api.post<GetAccountInfoModel>({ url: Api.ADD_DATAASSERT, data });
//删除数据资产目录
export const delDataAsset = (daCode: string) => api.del<GetAccountInfoModel>({ url: Api.DEL_DATAASSET + daCode });
//获取数据资产目录的标准编号下的详情
export const getDataAssetDetail = (dcCode: string) => api.get<GetAccountInfoModel>({ url: Api.GET_DATAASSETDETAIL + dcCode });
//根据条件查询数据资产表
export const selectDataAssert = (data: dataAssert) => api.post<GetAccountInfoModel>({ url: Api.SELECT_DATAASSERT, data });

/* 接口管理 */
// 查询接口列表
export const getInterfaceList = (data: interfaceType) => api.post<GetAccountInfoModel>({ url: Api.GET_INTERFACE, data });
// 改变接口状态
export const changeInterfaceState = (data: operationStatus) => api.put<GetAccountInfoModel>({ url: Api.CHANGE_INTERFACESTATUS, data });
// 批量分类
export const changeInterfaceBatchClassify = (data: batchClassify) => api.post<GetAccountInfoModel>({ url: Api.UPDATA_BATCHCLASSIFY, data });
//新增--编辑接口
export const addDataApi = (data: apiDetailType) => api.post<GetAccountInfoModel>({ url: Api.ADD_INTERFACE, data });
//校验接口是否存在
export const checkApi = (data: apiDetailType) => api.post<GetAccountInfoModel>({ url: Api.VERIFY_INTERFACE, data });
// 接口详情
export const getInterfacceDetail = (apiCode: string) => api.get<GetAccountInfoModel>({ url: Api.GET_INTERFACEDETAIL + apiCode });
// 接口测试
export const postInterfaceTest = (data: apiTest) => api.post<string>({ url: Api.POST_INTERFACETEST, data });
// 删除接口
export const delInterface = (apiCode: string) => api.del({ url: Api.DEL_INTERFACE + apiCode });
